/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package requestManager;

import app.Global;
import app.MyModel;
import entities.EmployeeShiftRequest;
import java.sql.Date;
import lib.JButtonTable.ButtonModel;

/**
 *
 * @author yoshi
 */
public class DisapproveButtonModel implements ButtonModel {

    private EmployeeShiftRequest request;

    public DisapproveButtonModel(EmployeeShiftRequest request) {
        this.request = request;
    }

    @Override
    public String getText() {
        if (!Global.getAuth().isDepartmentHead() && !Global.getAuth().isManager()) {
            return "Not allowed";
        } else if (this.getRequest().getFromSchedule().getEmployee().getRoll().isHead() && !Global.getAuth().isManager()) {
            return "Not allowed";
        } else if (request.getFromSchedule().getDate().compareTo(new Date(new java.util.Date().getTime())) <= 0
                || request.getRequestDate().compareTo(new Date(new java.util.Date().getTime())) <= 0) {
            return "Passed";
        } else if (this.getRequest().getStatus() == 0) {
            return "Disapproved";
        } else if (this.getRequest().getStatus() == 1) {
            return "Disapprove";
        } else if (this.getRequest().getStatus() == 2) {
            return "Disapprove";
        } else if (this.getRequest().getStatus() == 3) {
            return "Approved";
        } else {
            return "";
        }
    }

    @Override
    public boolean isEnable() {
        if (!Global.getAuth().isDepartmentHead() && !Global.getAuth().isManager()) {
            return false;
        } else if (this.getRequest().getFromSchedule().getEmployee().getRoll().isHead() && !Global.getAuth().isManager()) {
            return false;
        } else if (request.getFromSchedule().getDate().compareTo(new Date(new java.util.Date().getTime())) <= 0
                || request.getRequestDate().compareTo(new Date(new java.util.Date().getTime())) <= 0) {
            return false;
        } else if (this.getRequest().getStatus() == 0) {
            return false;
        } else if (this.getRequest().getStatus() == 1) {
            return true;
        } else if (this.getRequest().getStatus() == 2) {
            return true;
        } else if (this.getRequest().getStatus() == 3) {
            return false;
        } else {
            return false;
        }
    }

    public EmployeeShiftRequest getRequest() {
        return request;
    }
}
